package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ProductType;
import cn.wolfcode.trip.base.mapper.ProductTypeMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductTypeServiceImpl implements IProductTypeService {
    @Autowired
    private ProductTypeMapper productTypeMapper;

    @Override
    public PageInfo<ProductType> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<ProductType> list = productTypeMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void saveOrUpdate(ProductType entity) {
        if(entity.getId()!=null){
            productTypeMapper.updateByPrimaryKey(entity);
        }else {
            productTypeMapper.insert(entity);
        }
    }

    @Override
    public List<ProductType> listAll() {
        return productTypeMapper.selectAll();
    }
}
